package com.mapull.date;

import java.time.LocalDate;
import java.time.ZoneId;
import java.util.Date;

/**
 * 判断两个 Date 是否为同一天
 * @author mapull
 */
public class MapullSameDay {

    public static void main(String[] args) {
        Date date1 = new Date(1649019002100L);
        Date date2 = new Date(1649028051030L);
        Date date3 = new Date(1649232365000L);
        localDateSameDay(date1, date2);
        localDateSameDay(date1, date3);
    }

    private static void localDateSameDay(Date date1, Date date2) {
        LocalDate localDate1 = date1.toInstant().atZone(ZoneId.systemDefault())
                .toLocalDate();
        LocalDate localDate2 = date2.toInstant().atZone(ZoneId.systemDefault())
                .toLocalDate();
        boolean isSameDay = localDate1.isEqual(localDate2);
        System.out.printf("时间 %s 与 %s 是否为同一天 %s \n", date1, date2, isSameDay);
    }
}
